//
//  DLSetterViewController.m
//  XTXOneToOne
//
//  Created by Canny on 2018/10/29.
//  Copyright © 2018年 WK. All rights reserved.
//

#import "DLSetterViewController.h"
#import "LoginPassWordSetViewController.h"
#import "MoneyPassWordSetViewController.h"


@interface DLSetterViewController ()<UIAlertViewDelegate>

@end

@implementation DLSetterViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self setProperty];
    
    [self createUI];
    
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [UIApplication sharedApplication].statusBarHidden = NO;
    
    self.navigationController.navigationBar.translucent = YES;
    self.navigationController.navigationBarHidden=YES;

}

-(void)setProperty{
    
    self.view.backgroundColor=RGB(255, 255, 255);
    
    [UIApplication sharedApplication].statusBarHidden = NO;
    
    self.navigationController.navigationBar.translucent = YES;
    self.navigationController.navigationBarHidden=YES;
    
    self.baseVcTitle = @"设置";
}


-(void)createUI{
    
    UIButton * loginOutBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [loginOutBtn setTitle:@"退出登录" forState:UIControlStateNormal];
    [loginOutBtn setTitleColor:RGB(255, 255, 255) forState:UIControlStateNormal];
    [loginOutBtn addTarget:self action:@selector(btnClickAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:loginOutBtn];
    loginOutBtn.backgroundColor=RGB(99, 140, 220);
    loginOutBtn.tag=7001;
    loginOutBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    loginOutBtn.titleLabel.font=[UIFont systemFontOfSize:15];
    [loginOutBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_top).offset(200);
        make.left.equalTo(self.view.mas_left).offset(15);
        make.right.equalTo(self.view.mas_right).offset(-15);
        make.height.equalTo(@(50));
    }];
    
    [self setBtnWithIndex:1 andImageName:@"资金密码" andlabelText:@"重置"];
    [self setBtnWithIndex:2 andImageName:@"登录密码" andlabelText:@"修改"];

}

-(void)setBtnWithIndex:(NSInteger)index andImageName:(NSString *)ImageName andlabelText:(NSString *)text{
    
    UIButton * btn = [[UIButton alloc]init];
    [self.view addSubview:btn];
    CGFloat X = 15,Y = 65+35*index,W = G_SCREENWIDTH-15,H = 50;
    btn.frame = CGRectMake(X, Y, W, H);
    btn.tag = 7002+index;
    [btn addTarget:self action:@selector(btnClickAction:) forControlEvents:UIControlEventTouchUpInside];
    
    
    UILabel *label1 = [[UILabel alloc] init];
    label1.text = ImageName;
    label1.font = [UIFont systemFontOfSize:15];
    label1.textColor = RGB(30, 63, 89);
    [btn addSubview:label1];
    [label1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(btn.mas_left).offset(0);
        make.centerY.equalTo(btn.mas_centerY);
        make.width.equalTo(@(100));
        make.height.equalTo(@(18));
    }];
    
    
    UILabel *label = [[UILabel alloc] init];
    label.text = text;
    label.font = [UIFont systemFontOfSize:15];
    label.textColor = RGB(140, 159, 173);
    label.textAlignment=NSTextAlignmentRight;
    [btn addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(btn.mas_right).offset(-40);
        make.centerY.equalTo(btn.mas_centerY);
        make.width.equalTo(@(120));
        make.height.equalTo(@(30));
    }];
    
    
    UIImageView * imgVArrow = [[UIImageView alloc]init];
    [btn addSubview:imgVArrow];
    //    imgVArrow.backgroundColor=[UIColor cyanColor];
    [imgVArrow mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(btn.mas_right).offset(-15);
        make.centerY.equalTo(btn.mas_centerY);
        make.width.equalTo(@(6));
        make.height.equalTo(@(12));
    }];
    imgVArrow.image=[UIImage imageNamed:@"进入icon"];
    
}

-(void)btnClickAction:(UIButton *)btn{
    
    if (btn.tag == 7001) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"确定退出登录吗？" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
        alert.delegate=self;
        alert.alertViewStyle = UIAlertViewStyleDefault;
        [alert show];
        
    }else if(btn.tag == 7002){
        
        
    }else if (btn.tag == 7003){
        
        MoneyPassWordSetViewController * VC = [[MoneyPassWordSetViewController alloc]init];
        [self.navigationController pushViewController:VC animated:YES];
        
    }else if (btn.tag == 7004){
        
        LoginPassWordSetViewController * VC = [[LoginPassWordSetViewController alloc]init];
        [self.navigationController pushViewController:VC animated:YES];
    }
}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    
    __weak __typeof(self)wself = self;

    if (buttonIndex == 1) { //确认
        NSString * URL = [NSString stringWithFormat:@"%@user/logout",DEFAULTSEVERBASEURL];
        [MOLoadHttpsData GetHttpDataWithUrlStr:URL Dic:@{@"access_token":[LoginModel GetValue:DL_token]} SuccessBlock:^(id  _Nonnull responseObject) {
//            NSDictionary * dic = responseObject;
//            NSString * code = [NSString stringWithFormat:@"%@",dic[@"code"]];
//            if ([code isEqualToString:@"0"]) {
                [LoginModel loginOutData];
                [wself.navigationController popViewControllerAnimated:YES];
//            }
            
        } FailureBlock:^(id  _Nonnull error) {
            [LoginModel loginOutData];
            [wself.navigationController popViewControllerAnimated:YES];
        }];
        
    }

}

//-(void)goBackAction{
//    [super goBackAction];
//    [self.navigationController popViewControllerAnimated:YES];
//    
//}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
